﻿using UnityEngine;

namespace Cheng
{
    /// <summary>
    /// 游戏入口。
    /// </summary>
    public partial class GameEntry : MonoBehaviour
    {
        //public ReferenceCollector ConfigsCollector;
        private void Start()
        {
            // 初始化内置组件
            InitBuiltinComponents();

            // 初始化自定义组件
            InitCustomComponents();

            // 初始化自定义调试器
            InitCustomDebuggers();


            //EGamePlay.MasterEntity.Create();
            //EGamePlay.Entity.Create<ET.TimerComponent>();
            //EGamePlay.Entity.Create<EGamePlay.Combat.CombatContext>();
            //EGamePlay.MasterEntity.Instance.AddComponent<EGamePlay.Combat.ConfigManageComponent>(ConfigsCollector);
        }

        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape) && UI.GetUIForm(UIFormId.LogoForm)==null)
            {
                var dialog = new DialogParams();
                dialog.CancelText = "取消";
                dialog.ConfirmText = "确定";
                dialog.Mode = 2;
                dialog.Message = "是否确定退出游戏？";
                dialog.OnClickConfirm = (obj) => {
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPlaying = false;
#else

                    Application.Quit();
#endif
                };
                UI.OpenDialog(dialog);

                return;
            }

          
        }

        private void OnApplicationQuit()
        {

        }
    }
}